package com.aaa.stock.service.prod.impl;

import com.aaa.entity.Producer;
import com.aaa.entity.Role;
import com.aaa.stock.dao.prod.ProducerDao;
import com.aaa.stock.service.prod.ProdcerService;
import com.aaa.stock.vo.ProducerVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.*;
import java.util.function.Function;

@Service
public class ProducerServiceImpl extends ServiceImpl<ProducerDao,Producer> implements ProdcerService {
    @Autowired
    private ProducerDao producerDao;
//分页查
    @Override
    public Result<IPage<Producer>> findByListtion(Integer currentPage, Integer pageSize, ProducerVo producerVo) {
        IPage<Producer> page=new Page<>(currentPage,pageSize);
        QueryWrapper<Producer> wrapper=new QueryWrapper<>();
        if(StringUtils.hasText(producerVo.getProducerName())){
            wrapper.like("producer_name",producerVo.getProducerName());
        }
        if(StringUtils.hasText(producerVo.getProducerTel())){
            wrapper.eq("producer_tel",producerVo.getProducerTel());
        }
        if(StringUtils.hasText(producerVo.getKeywords())){
            wrapper.eq("keywords",producerVo.getKeywords());
        }
        if(Objects.nonNull(producerVo.getCreateTime())&&producerVo.getCreateTime().length==2){
            wrapper.between("create_time",producerVo.getCreateTime()[0],producerVo.getCreateTime()[1]);
        }
        if(Objects.nonNull(producerVo.getStatus())){
            wrapper.eq("status",producerVo.getStatus());
        }

        IPage<Producer> page1 = producerDao.selectPage(page, wrapper);
        return new Result<IPage<Producer>>(2000,"查询厂家成功",page1);
    }
//删
    @Override
    public Result<Map<String,Object>> deletPro(Long producterIds) {
        producerDao.deletePro(producterIds);
        return new Result<>(2000,"删除成功");
    }

    @Override
    public Result<List<Producer>> selectAllProdName() {
        QueryWrapper<Producer> wrapper=new QueryWrapper<>();
        wrapper.eq("status",0);
        List<Producer> producers=producerDao.selectList(wrapper);
        return new Result<>(2000,"查询角色",producers);
    }

}
